<template>
	<view class="content">
		<view class="report_input">
			<view class="report_input_title">
				<text>详细信息描述</text>
				<text>{{commentObj.comment.length}}/200</text>
			</view>
			<textarea maxlength="200" v-model="commentObj.comment" placeholder="请详细描述您的评论内容" />
		</view>
		<view class="start_box">
			<view class="start_box_title">
				<text>请您评星</text>

			</view>
			<view class="start">
				<uni-rate :size="25" :value="commentObj.commentScore" @change="onChange"/>
			</view>
		</view>
		<view style="box-sizing: border-box;padding:0 30rpx;position: absolute;bottom: 58rpx;left: 0;right: 0;">
			<view class="pay_btn" @click="submitFun">
				<text> 确定</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: "",
				commentObj: {
					commentScore: 5,
					comment: "",
					areaCode: "110101"
				},
				type:"",//评论类型 0课程 1品牌
			}
		},

		onLoad(data) {
			this.id = data.id;
			this.type=data.type;
			if(uni.getStorageSync('cityChange')){
				this.cityObj=JSON.parse(uni.getStorageSync('cityChange'))
				this.cityCode=this.cityObj.code;
			}
		},
		onShow() {

		},
		methods: {
			onChange(e) {
				console.log(e)
				this.commentObj.commentScore=e.value;
			},
			//提交评论
			submitFun() {
				console.log(this.commentObj.commentScore)
				this.$http.post('/api/user/userComment',{
						...this.commentObj,
						areaCode:this.cityCode,
						"commentType": this.type,
						"targetId": this.id
				},'application/json').then((data)=>{
					if(data.data.code==200){
						uni.showToast({
							title: '评论成功!',
							icon: "success",
							duration: 2000,

						});
						setTimeout(()=>{
							uni.navigateBack();

						},1000)
					}else{
						uni.showToast({
							title: data.data.message,
							icon: "none",
							duration: 2000,

						});
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/css/comment.scss'
</style>
